package com.company.阻塞队列;

import com.company.jdk8.test;

import javax.sound.midi.Soundbank;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @ProjectName: 复习java
 * @Package: com.company.阻塞队列
 * @ClassName: demo1
 * @Author: wym
 * @Date: 2020/9/29 14:18
 * @Version: 1.0
 *
 * 1 队列
 *
 * 2 阻塞队列
 *    2.1 阻塞队列 有没有 好的一面
 *    2.2 不得阻塞 ，你如何管理
 *  Collecation
 *      ||
 *      Queue
 *      \\
 *      BlockingQueue 7个实现类
 *    ArrayBlockingQueue
 *    LinkedBlockingQueue
 *
 *
 */
class BlockingQueueDemo {
    public static void main(String[] args)  throws Exception{
//        List<String> list1=new CopyOnWriteArrayList();
//        System.out.println(Integer.MAX_VALUE);
        BlockingQueue<String> blockingQueue=new ArrayBlockingQueue<>(3);
        //异常组
        System.out.println(blockingQueue.add("a"));
        System.out.println(blockingQueue.add("b"));
        System.out.println(blockingQueue.add("c"));
        //返回第一个,并检查
        System.out.println(blockingQueue.element());
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        //特殊值
        System.out.println(blockingQueue.offer("d"));
        //peek 第一个
        System.out.println(blockingQueue.peek());
        //拿到这个 poll
        System.out.println(blockingQueue.poll());
    }
}
